'use strict'
import React from 'react'
import style from '../css.css'
import { goIndex, goLive } from "../../config/goto"
import config from "../../config"
class List extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
    }
    this._handleItem = this._handleItem.bind(this)
  }
  _handleItem() {
    // 正在直播的主播进入／或者在糗事百科的直播页面进入的不响应
    if (config.isAnchor || config.qiubaizhibo) {
      console.log("正在直播的主播进入／或者在糗事百科的直播页面进入的不响应");
      return
    }
    if (config.inapp_info) {
      console.log("在自家APP内，跳转直播页／个人主页");
      let { uid, source, platform_id, live } = this.props.item
      if (uid == null || source == null || platform_id == null) { return }
      else {
        var args = { uid, source, platform_id }
        if (live == 1) {
          // 直播间
          goLive(args)
        }
        else {
          // 个人主页
          goIndex(args)
        }
      }

      return
    }
    else {
      console.log("没有在自家APP内，跳去下载");
      window.location.href = config.download
      return
    }
  }
  _renderLive() {
    let { live } = this.props.item
    if (live == 1) {
      return (
        <div className={style.itemLive}></div>
      )
    }
  }
  render() {
    let { item, index, nav } = this.props
    let { headurl, name, num } = item
    return (
      <div className={style.list} onClick={this._handleItem}>
        <span className={index == 0 ? style.listNo : index == 1 ? style.listNo1 : index == 2 ? style.listNo2 : style.listNo3}>{index > 2 ? 'NO.' + (index + 1) : ''}</span>
        <div className={style.itemHeader}>
          <img src={headurl} className={`${style.listImg} ${index == 0 ? style.listImg1 : index == 1 ? style.listImg2 : ''}`} />
          {this._renderLive()}
        </div>

        <span className={style.listName}>{name}</span>
        <span >{num}</span>
      </div>
    )
  }
}
export default List
